package pbx.job.process;

import java.util.List;

import javax.ejb.AccessTimeout;
import javax.ejb.EJB;
import javax.ejb.Singleton;

import pbx.model.QueueLog;
import pbx.service.QueueLogProcessService;
import pbx.service.QueueLogService;
import softswitch.ws.CallSummaryService;
import softswitch.ws.SoftswitchService;


@Singleton
public class QueueLogWorker {

	@EJB
	QueueLogService queueLogService;
	
	@EJB
	SoftswitchService softSwitchService;
	
	@EJB
	QueueLogProcessService queueLogProcessService;
	
	@EJB
	CallSummaryService callSummaryService;

	
	@AccessTimeout(0)
	public void processQueueLogs() throws InterruptedException {
		
		System.out.println("RUNNING PROCESS QUEUELOG WORKER");
		
		List<QueueLog> queuelogs =  queueLogService.listForProcess(100);
		if(queuelogs!=null){
			Integer size = queuelogs.size();
			Integer processed = 0;
			
			System.out.println("QUEUELOG'S SIZE " + size);
			for(QueueLog queuelog:queuelogs){
				
				System.out.println(queuelog.getCallid() + " - " + queuelog.getEvent());
				
				queueLogProcessService.process(queuelog);
				
				processed ++;
				
				System.out.println("QUEUELOG'S PROCESCED " + processed + "/" + size);
				
			}
		}
		
	}//reprocessCDR()
	
	

}